#!/bin/bash

pwd=`pwd`
cd dependency
if [ ! -d "protobuf-2.6.1" ]; then
	tar -xvzf protobuf-2.6.1.tar.gz
fi
cd protobuf-2.6.1

./configure --prefix=${pwd}
make -j 2 && make install

# python
cp ../descriptor_pb2.py python/google/protobuf
cp -rf python/google ../../
cd ../../


# copy lua-5.1 include lib bin
cd dependency
if [ ! -d "lua-5.1.5" ]; then
	tar -xvzf lua-5.1.5.tar.gz
fi
cd lua-5.1.5
make linux -j 2 && make local
cd ../../
cp -rf dependency/lua-5.1.5/include/* include
cp -rf dependency/lua-5.1.5/lib/* lib
cp -rf dependency/lua-5.1.5/bin/* bin


# protoc-gen-lua
if [ ! -d "protobuf_lua" ]; then
	mkdir protobuf_lua
fi
cd dependency/protoc-gen-lua/protobuf
make
cd ../../../
cp -rf dependency/protoc-gen-lua/plugin dependency/protoc-gen-lua/protobuf protobuf_lua


# protobuf-c
cd dependency
if [ ! -d "protobuf-c-1.1.1" ]; then
	tar -xvzf protobuf-c-1.1.1.tar.gz
fi
cd protobuf-c-1.1.1
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:${pwd}/lib/pkgconfig
./configure --prefix=${pwd}
make -j 2 && make install